package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.HotsCircleDataBean;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 08 月 28.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.adapter
 * 工程名 welbeing_pregnant
 */
public class PopularCircleAdapter extends RecyclerView.Adapter<PopularCircleAdapter.ViewHolder> implements View.OnClickListener {
    private static final String TAG = "PopularCircleAdapter";
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private Context mcontext;
    private List<HotsCircleDataBean.DataBean> mlist = new ArrayList();

    public PopularCircleAdapter( Context paramContext) {
        this.mcontext = paramContext;
    }

    public  void addItem(List<HotsCircleDataBean.DataBean> mlistBean){
        mlist.clear();
        mlist.addAll(mlistBean);
        notifyDataSetChanged();
    }
    public int getItemCount() {
        return this.mlist.size();
    }

    public void onBindViewHolder(ViewHolder viewHolder, int postion) {
        viewHolder.tv_name.setText(mlist.get(postion).cat_name);
        Glide.with(this.mcontext).load("http://oop.welbeing.cn/Public/Uploads/" + mlist.get(postion).url).into(viewHolder.iv_pictrue);
    }

    public void onClick(View paramView) {
        if (this.mOnItemClickListener != null) {
            this.mOnItemClickListener.onItemClick(paramView);
        }
    }

    public ViewHolder onCreateViewHolder(ViewGroup paramViewGroup, int paramInt) {
      View  view = LayoutInflater.from(paramViewGroup.getContext()).inflate(R.layout.item_release_popular_circle_recyclerview, paramViewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener paramOnRecyclerViewItemClickListener) {
        this.mOnItemClickListener = paramOnRecyclerViewItemClickListener;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_pictrue;
        private TextView tv_name;
        public ViewHolder(View paramView) {
            super(paramView);
          tv_name = (TextView) paramView.findViewById(R.id.item_release_popular_circle_recyclerview_tv_name);
           iv_pictrue = (ImageView) paramView.findViewById(R.id.item_release_popular_circle_recyclerview_iv_pictrue);

        }
    }
}
